package org.gitman.agentplatform.ui.actions;

import java.awt.event.ActionEvent;

import javax.swing.JTable;

import org.gitman.agentplatform.agent.api.Agent;
import org.gitman.agentplatform.agent.api.InternalAgentInfo;
import org.gitman.agentplatform.core.AgentManager;

public class EditAgentAction extends UIAction{

	public EditAgentAction() {
		super("Edit");
	}
	
	@Override
	public void actionPerformed(ActionEvent e) {
		JTable table = mainFrame.getSimulationPanel().getTable();
		int row = table.getSelectedRow();
		if(row != -1){ // there is some row selected
			mainFrame.getSimulationPanel().showDetailsAgentPanel();
			mainFrame.getSimulationPanel().revalidate();
			
			Integer id = (Integer) table.getModel().getValueAt(row, 0);
			AgentManager agentManager = platformManager.getSimulation().getAgentManager();		
			InternalAgentInfo info = agentManager.getAgentInfo(id);
			Agent agent = agentManager.getAgent(id);
			
			mainFrame.getSimulationPanel().loadAgent2Edit(info, agent.getClass().getSimpleName());
		}
	}

}
